//package com.lin.config;
//
//import com.lin.common.rest.BaseReqMsg;
//import com.lin.common.rest.BaseResMsg;
//import com.lin.common.rest.ReqMsg;
//import com.lin.common.rest.ResMsg;
//import com.lin.handler.ModifyBodyHandler;
//import com.lin.handler.ModifyResponseBodyHandler;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.gateway.route.RouteLocator;
//import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.MediaType;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//
//@Configuration
//public class GatewayFilterConfig {
//
//    private static final Logger log = LoggerFactory.getLogger(GatewayFilterConfig.class);
//    @Value("${cs.gateway.url}")
//    private String struri;
//
//    @Value("${cs.path.filter.unverify}")
//    private String unverify;
//
//    /**
//     * 如果请求路径包含‘unverify’则不做任何加密处理；否则则把BaseReqMsg中的data修改为进行加密转换为base64进行后，存储在BaseReqMsg中的data中；
//     * @param builder
//     * @return
//     */
//    @Bean
//    public RouteLocator modifyRequestBodyRoutes(RouteLocatorBuilder builder) {
//        return builder.routes().route("modifybody", r -> r.path("/customerservice/**")
//                .filters(f -> f.modifyRequestBody(BaseReqMsg.class, BaseReqMsg.class, MediaType.APPLICATION_JSON_VALUE, (serverWebExchange, s) -> {
//                    log.info("modifyRequestBody 22");
//                    String path = serverWebExchange.getRequest().getPath().value();
//                    boolean containsFlag = path.contains(unverify);
//                    if(containsFlag){
//                        //不做任何加密操作
//                        return Mono.just(s);
//                    }else{
//                        return ModifyBodyHandler.getbean("modifyRequestBodyHandler").modifyBody(s);
//                    }
//                }).modifyResponseBody(ResMsg.class, BaseResMsg.class,
//                        (exchange, s) -> {
//                            log.info("modifyResponseBody 11");
//                            return Mono.just(null);
//                        })).uri(struri)).build();
//    }
//
//    private Mono<BaseReqMsg> buildMono(String unverify,ServerWebExchange serverWebExchange,BaseReqMsg baseReqMsg){
//        String path = serverWebExchange.getRequest().getPath().value();
//        boolean containsFlag = path.contains(unverify);
//        if(containsFlag){
//            //不做任何加密操作
//            return Mono.just(baseReqMsg);
//        }else{
//            return ModifyBodyHandler.getbean("modifyRequestBodyHandler").modifyBody(baseReqMsg);
//        }
//    }
//
//}
